package ase.eleitweg;

import java.io.File;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.*;

import ase.eleitweg.common.*;
import ase.eleitweg.server.db.DatabaseFactory;
import ase.eleitweg.server.db.ELeitwegDAO;

public class SerializeTestData {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		ELeitwegDAO db = DatabaseFactory.getDB();
		
		List<User> users = db.getUsers();
		List<Group> groups = db.getGroups();
		List<Workflow> wfs = db.getAllWorkflows();
		List<Run> runs = db.getInstances();
		System.out.println(runs.get(0).getWf().getNodes().size());
		List<Document> docs = new Vector<Document>();
		for(Run x : runs) {
			for(Document d : db.getDocuments(x.getId())) {
				docs.add(d);
			}
		}
		File f = new File(System.getProperty("user.dir") + "/dataTestFilled/TestData.bin");
		System.out.println(f.exists());
		System.out.println(f.getCanonicalPath());
		System.out.println(f.createNewFile());
		FileOutputStream fos = new FileOutputStream(f);
		ObjectOutputStream oos = new ObjectOutputStream(fos);
		oos.writeObject(users);
		oos.writeObject(groups);
		oos.writeObject(wfs);
		oos.writeObject(runs);
		oos.writeObject(docs);
		oos.close();
		fos.close();
	}

}
